
package com.operatehistorymodule.dao;
import com.operatehistorymodule.bean.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import util.*;
public class TbOperateHistoryDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbOperateHistory tbOperateHistory=null;
    private List<TbOperateHistory> tbOperateHistoryList=null;

    public boolean add(TbOperateHistory inTbOperateHistory){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_OperateHistory(ModuleName,UserId,UserName,UserAction,UserActionName,CreateTime) values(?,?,?,?,?,?)";
        pt = conn.prepareStatement(sql);
        
        pt.setString(1,inTbOperateHistory.getModuleName());
        pt.setInt(2,inTbOperateHistory.getUserId());
        pt.setString(3,inTbOperateHistory.getUserName());
        pt.setInt(4,inTbOperateHistory.getUserAction());
        pt.setString(5,inTbOperateHistory.getUserActionName());
        pt.setString(6,inTbOperateHistory.getCreateTime());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public boolean del(int inOperateHistoryId){
        return UtilDAO.del("Tb_OperateHistory", "OperateHistoryId", inOperateHistoryId);
    }
    public boolean edit(TbOperateHistory inTbOperateHistory){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_OperateHistory set OperateHistoryId=?,ModuleName=?,UserId=?,UserName=?,UserAction=?,UserActionName=?,CreateTime=? where OperateHistoryId=?";
        pt = conn.prepareStatement(sql);
        
        pt.setInt(1,inTbOperateHistory.getOperateHistoryId());
        pt.setString(2,inTbOperateHistory.getModuleName());
        pt.setInt(3,inTbOperateHistory.getUserId());
        pt.setString(4,inTbOperateHistory.getUserName());
        pt.setInt(5,inTbOperateHistory.getUserAction());
        pt.setString(6,inTbOperateHistory.getUserActionName());
        pt.setString(7,inTbOperateHistory.getCreateTime());
        pt.setInt(8,inTbOperateHistory.getOperateHistoryId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public TbOperateHistory getTbOperateHistoryByOperateHistoryId(int inOperateHistoryId) {
        tbOperateHistory=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_OperateHistory where OperateHistoryId=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inOperateHistoryId);
            rs = pt.executeQuery();
            while (rs.next()) {
                if (tbOperateHistory == null)tbOperateHistory = getTbOperateHistory(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbOperateHistory;
    }
    public List<TbOperateHistory> getTbOperateHistoryAll() {
        tbOperateHistoryList=new ArrayList<TbOperateHistory>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_OperateHistory";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbOperateHistoryList.add(getTbOperateHistory(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbOperateHistoryList;
    }
    public List<TbOperateHistory> getTbOperateHistoryAll(VskPage vp) {
        tbOperateHistoryList=new ArrayList<TbOperateHistory>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_OperateHistory";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_OperateHistory", "OperateHistoryId"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbOperateHistoryList.add(getTbOperateHistory(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbOperateHistoryList;
    }
    public TbOperateHistory getTbOperateHistory(ResultSet rs) throws Exception{
        TbOperateHistory tbOperateHistory = new TbOperateHistory();
        tbOperateHistory.setOperateHistoryId(rs.getInt("OperateHistoryId"));
        tbOperateHistory.setModuleName(rs.getString("ModuleName"));
        tbOperateHistory.setUserId(rs.getInt("UserId"));
        tbOperateHistory.setUserName(rs.getString("UserName"));
        tbOperateHistory.setUserAction(rs.getInt("UserAction"));
        tbOperateHistory.setUserActionName(rs.getString("UserActionName"));
        tbOperateHistory.setCreateTime(rs.getString("CreateTime"));
        return tbOperateHistory;
    }
}
